package com.burgeon.backend.SHOP.controller;


import com.burgeon.backend.SHOP.entity.Refund;
import com.burgeon.backend.SHOP.entity.RefundVO;
import com.burgeon.backend.SHOP.service.RefundService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("shop/refund")
public class RefundController extends BaseController{
    @Autowired
    private RefundService refundService;

    @RequestMapping("sendMail")
    public ResponseResult<Void> sendMail(String id,String oid,String FASTNO,String FASTGS,HttpSession session) {
        if (null == session.getAttribute("uid")) {
            return new ResponseResult<>(NOTLOG);
        }
        String uid = session.getAttribute("uid").toString();
        String token = session.getAttribute("token").toString();
        refundService.sendMail(id,oid,FASTNO,FASTGS,token,uid);

        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("mailData")
    public ResponseResult<HashMap> mailData(String id, HttpSession session) {
        if (null == session.getAttribute("uid")) {
            return new ResponseResult<>(NOTLOG);
        }
        String token = session.getAttribute("token").toString();

        HashMap data = refundService.getItemMailData(id, token);
        return new ResponseResult<HashMap>(SUCCESS,data);
    }

    @RequestMapping("test")
    public ResponseResult<Void> test(String id) {

        refundService.test(id);
        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("item")
    public ResponseResult<RefundVO> getItem(String id, HttpSession session) {
        if (null == session.getAttribute("uid")) {
            return new ResponseResult<>(NOTLOG);
        }
        String token = session.getAttribute("token").toString();

        RefundVO data = refundService.getItemData(id, token);
        return new ResponseResult<RefundVO>(SUCCESS,data);
    }

    @RequestMapping("data")
    public ResponseResult<List<Refund>> showSeckill(HttpSession session) {
        if (null == session.getAttribute("uid")) {
            return new ResponseResult<>(NOTLOG);
        }
        String token = session.getAttribute("token").toString();
        String uid = session.getAttribute("uid").toString();
        List<Refund> data = refundService.getData(uid, token);
        return new ResponseResult<List<Refund>>(SUCCESS,data);
    }
//发起申请
    @RequestMapping("apply")
    public ResponseResult<List<Refund>> applyForGoods(String id,String num,String cause,HttpSession session) {

        if (null == session.getAttribute("uid")) {
            return new ResponseResult<>(NOTLOG);
        }
        String uid = session.getAttribute("uid").toString();
        String token = session.getAttribute("token").toString();
        refundService.applyForGoods(id,num, cause,token,uid);

        return new ResponseResult<List<Refund>>(SUCCESS);
    }


}
